#pragma once

#include <QByteArray>
#include <QDataStream>
#include <QHostAddress>
#include <QDateTime>
#include <QString>
#include <memory>
#include "PlayerGameData.h"
#include "MonsterData.h"

// 精简的数据包类型枚举
enum class PacketType : quint16 
{
    PLAYER_JOIN = 10,
    PLAYER_LEAVE = 11,
    GAME_START = 100,
    GAME_STATUS = 101,
    ATTACK = 102,
    LEVEL_UP = 103,
    COMBAT_MESSAGE = 104  // 新增：战斗过程消息
};

// 精简的玩家信息结构
struct PlayerInfo 
{
    quint32 playerId;
    QString playerName;
    QHostAddress address;
    quint16 port;
    PlayerGameData gameData;    // 游戏数据
    MonsterData currentMonster; // 当前怪物
    
    PlayerInfo();
    PlayerInfo(quint32 id, const QString& name, const QHostAddress& addr, quint16 p);
};

// 游戏数据包基类
struct GamePacket 
{
    PacketType type;
    quint32 playerId;
    quint32 timestamp;
    
    GamePacket();
    GamePacket(PacketType t, quint32 id);
    virtual ~GamePacket() = default;
    
    virtual QByteArray serialize() const;
    static std::unique_ptr<GamePacket> deserialize(const QByteArray& data);
};

// 游戏状态数据包
struct GameStatusPacket : GamePacket 
{
    PlayerGameData playerData;
    MonsterData monsterData;
    QString message;
    
    GameStatusPacket();
    GameStatusPacket(quint32 id, const PlayerGameData& pData, const MonsterData& mData, const QString& msg = "");
    
    QByteArray serialize() const override;
};

// 攻击数据包
struct AttackPacket : GamePacket 
{
    quint32 damage;
    quint32 targetHealth;
    QString message;
    
    AttackPacket();
    AttackPacket(PacketType type, quint32 id, quint32 dmg, quint32 health, const QString& msg = "");
    
    QByteArray serialize() const override;
};

// 升级数据包
struct LevelUpPacket : GamePacket 
{
    PlayerGameData newPlayerData;
    QString message;
    
    LevelUpPacket();
    LevelUpPacket(quint32 id, const PlayerGameData& data, const QString& msg = "");
    
    QByteArray serialize() const override;
};

// 战斗消息数据包
struct CombatMessagePacket : GamePacket 
{
    QString message;
    
    CombatMessagePacket();
    CombatMessagePacket(quint32 id, const QString& msg);
    
    QByteArray serialize() const override;
}; 